package com.centerm.structure.api;

import com.centerm.common.constant.Constant;
import com.centerm.common.constant.error.GlobalErrorEnum;
import com.centerm.common.exception.MyRuntimeException;
import com.centerm.common.view.JSONResponse;
import com.centerm.structure.domain.User;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractAPI {

    private static final String success = null;

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    protected <T> JSONResponse<T> success(T result) {
        return new JSONResponse<>(result);
    }

    protected JSONResponse<String> success() {
        return success(success);
    }
    
    protected User getUser(HttpSession session) {
    	Object obj = session.getAttribute(Constant.SESSION_USER);
		if(obj == null) {
			throw new MyRuntimeException(GlobalErrorEnum.LOGIN_ERROR);
		}
		return (User) obj;
    }
}
